package com.ruoyi.hr.controller.hr.entryexitmanage.quitmanage;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.entryexitmanage.quitmanage.QuitManageService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @author zeo
 * @explain 离职管理
 * @date 2020/3/9
 */
@Controller
@RequestMapping("/quitManage/quitEmpRegister")
public class QuitEmpRegisterController extends BaseController {

    @Autowired
    AuthorityService authorityService;

    @Autowired
    QuitManageService quitManageService;

    private String prefix = "hr/entryexitmanage/quitManage";


    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String quitEmpRegister() {
        return prefix + "/quitEmpRegister";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(quitManageService.getQuitEmpData(map, authority));
    }

    @GetMapping("/add")
    public String addQuitEmp() {
        return prefix + "/addQuitEmp";
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("editQuitEmp", quitManageService.getQuitEmpById(id));
        return prefix + "/editQuitEmp";
    }

    @RequestMapping("/addQuitEmp")
    @ResponseBody
    public TableDataInfo findQuitEmp(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(quitManageService.addQuitEmp(map, authority));
    }

    /**
     * 执行变更员工存储过程
     */
    @PostMapping("/addQuitEmpProcedure")
    @ResponseBody
    public BaseResult addQuitEmpProcedure(String allEid) {
        return quitManageService.addQuitEmpProcedure(allEid);
    }


    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map){
        return toAjax(quitManageService.editQuitEmpInfo(map));
    }



    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(quitManageService.deleteQuitEmp(ids));
    }

    /**
     * 数据确认,取消确认,执行
     */
    @PostMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId, String procedure) {
        return quitManageService.procedure(allId, procedure);
    }


    @GetMapping("/quitEmpHistory")
    public String quitEmpHistory() {
        return prefix + "/quitEmpRegisterHistory";
    }

    @RequestMapping("/quitEmpHistory")
    @ResponseBody
    public TableDataInfo quitEmpHistory(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(quitManageService.quitEmpHistory(map, authority));
    }

}
